import React, { memo } from "react";
import routesConfig from "./config";
import { Route, Switch } from "react-router-dom";
function RouteWithSubRoutes(route) {
    return (
        <Route
            path={route.path}
            render={(props) => <route.component {...props} routes={route.routes}>
                {route.children ? route.children.map((child, i) => (
                    /** 递归传入子组件 */
                    <RouteWithSubRoutes key={i} {...child} />
                )) : ''}
            </route.component>}
        />
    );
}

const RouterPage = memo(() => {
    return (
        <Switch>
            {routesConfig.map((item, index) => (
                item.component ? <RouteWithSubRoutes key={index} {...item} /> : null
            ))}
        </Switch>
    );
});

export default RouterPage;